import java.util.Random;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/9 9:55
 * @description:
 */
public class Solution470 {
    private static final Random random = new Random();
    public int rand10() {
        int result;
        do {
            // 生成1-49的均匀随机数
            int num = (rand7() - 1) * 7 + rand7();
            // 只保留1-40，映射到1-10
            if (num <= 40) {
                result = num % 10 + 1;
                break;
            }
        } while (true);
        return result;
    }
    public int rand7(){
        // nextInt(7)生成0-6之间的随机数，加1后范围变为1-7
        return random.nextInt(7) + 1;
    }

    public static void main(String[] args) {
        Solution470 solution = new Solution470();
        int totalTests = 10_000_000; // 大量测试以保证准确性
        int[] counts = new int[11]; // 索引1-10存储对应数字的计数

        // 执行测试
        for (int i = 0; i < totalTests; i++) {
            int num = solution.rand10();
            counts[num]++;
        }

        // 输出结果
        System.out.println("rand10()概率测试结果（总次数：" + totalTests + "）：");
        for (int i = 1; i <= 10; i++) {
            double probability = (double) counts[i] / totalTests;
            System.out.printf("数字 %d: 出现 %d 次，频率 %.6f（理论值：%.6f）%n",
                    i, counts[i], probability, 0.1);
        }
    }
}
